'use strict';

const db = uniCloud.database();
const collection = db.collection('users');
exports.main = async (event, context) => {

	const {
		userId,
		blogId,
		type
	} = event;

	if (type === 'add') {
		return await collection.doc(userId).update({ likeBlogs: db.command.addToSet(blogId) });
	} else if (type === 'remove') {
		return await collection.doc(userId).update({ likeBlogs: db.command.pull(blogId) });
	} else {
		return {
			code: 400,
			msg: 'type参数错误'
		};
	}
	return {
		code: 0,
		msg: '成功',
		data: res.data
	};
};